.NET Framework Class Library |
Parallel..::.ForEach<(Of <(TSource>)>) Method (IEnumerable<(Of <(TSource>)>), ParallelOptions, Action<(Of <(TSource>)>)) |
Parallel Class See Also Send Feedback |
Executes a for each operation on an IEnumerable<(Of <(TSource>)>)
in which iterations may run in parallel.
Namespace:
System.Threading.Tasks
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Shared Function ForEach(Of TSource) ( _ source As IEnumerable(Of TSource), _ parallelOptions As ParallelOptions, _ body As Action(Of TSource) _ ) As ParallelLoopResult |
C# |
---|
public static ParallelLoopResult ForEach<TSource>( IEnumerable<TSource> source, ParallelOptions parallelOptions, Action<TSource> body ) |
Parameters
- source
- Type: System.Collections.Generic..::.IEnumerable<(Of <(TSource>)>)
An enumerable data source.
- parallelOptions
- Type: System.Threading.Tasks..::.ParallelOptions
A ParallelOptions instance that configures the behavior of this operation.
- body
- Type: System..::.Action<(Of <(TSource>)>)
The delegate that is invoked once per iteration.
Type Parameters
- TSource
- The type of the data in the source.
Return Value
A ParallelLoopResult structure that contains information on what portion of the loop completed.Remarks
The body delegate is invoked once for each element in the source
enumerable. It is provided with the current element as a parameter.
Exceptions
Exception | Condition |
---|---|
System..::.ArgumentNullException | The exception that is thrown when the source argument is null. |
System..::.ArgumentNullException | The exception that is thrown when the parallelOptions argument is null. |
System..::.ArgumentNullException | The exception that is thrown when the body argument is null. |
System..::.OperationCanceledException | The exception that is thrown when the CancellationToken in the parallelOptions argument is set |
System..::.AggregateException | The exception that is thrown to contain an exception thrown from one of the specified delegates. |
System..::.ObjectDisposedException | The exception that is thrown when the the CancellationTokenSource associated with the the CancellationToken in the parallelOptions has been disposed. |